package com.fengye.school.controller;

import com.fengye.school.model.school.Subject;
import com.fengye.school.response.ResponsePageResult;
import com.fengye.school.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 课纲控制器
 * @author sky
 * @date 2021/4/22 13:22
 */
@RestController
@RequestMapping("/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    @PostMapping("/save")
    public Subject save(@RequestBody Subject school) {
        return subjectService.save(school);
    }

    @GetMapping("/list")
    public List<Subject> list() {
        return subjectService.list();
    }

    @GetMapping("/list/page")
    public ResponsePageResult<Subject> listByPage(int page, int limit) {
        return subjectService.listByPage(Math.max((page - 1), 0), limit);
    }

    @DeleteMapping("/delete/all")
    public void deleteAll(Long[] ids){
        Arrays.stream(ids).forEach(System.out::println);
        subjectService.deleteAll(ids);
    }

    @DeleteMapping("/delete/id/{id}")
    public void deleteById(@PathVariable(name = "id", required = true)Long id){
        subjectService.deleteById(id);
    }
    // @PostMapping("/save")
    // public Subject save(@RequestBody Subject subject){
    //     return subjectService.save(subject);
    // }
    //
    //
    //
    // @GetMapping("/list")
    // public List<Subject> list() {
    //     return subjectService.list();
    // }
    //
    // @GetMapping("/list/page")
    // public PageVO<Subject> listForPage(@RequestParam(name = "page", defaultValue = "1") int page,
    //                                    @RequestParam(name = "size", defaultValue = "5")int size) {
    //     return subjectService.listForPage(page, size);
    // }
}
